// video/pages/result/result.js
Page({
    data: {
      totalScore: 0,
      resultTitle: "",
      resultDesc: "",
      resultColor: "",
      resultIcon: ""
    },
  
    onLoad() {
      // 获取存储的分数
      const totalScore = wx.getStorageSync('totalScore');
      
      // 如果没有分数，跳转回测评页
      if (totalScore === '' || totalScore === null) {
        wx.navigateTo({
          url: '/pages/quiz/quiz'
        });
        return;
      }
  
      // 设置结果数据
      this.setData({ totalScore });
      this.setResultInfo(totalScore);
    },
  
    // 设置结果信息
    setResultInfo(score) {
      if (score >= 13) {
        this.setData({
          resultTitle: "知识熟练",
          resultDesc: "恭喜你对番茄炒蛋做法了如指掌，快去大展身手吧！",
          resultColor: "#52c41a",
          resultIcon: "/images/success.png"
        });
      } else if (score >= 9 && score <= 12) {
        this.setData({
          resultTitle: "知识一般",
          resultDesc: "基本掌握做法要点，再复习一下细节会更完美哦~",
          resultColor: "#faad14",
          resultIcon: "/images/warning.png"
        });
      } else {
        this.setData({
          resultTitle: "需要加强",
          resultDesc: "建议重新观看食谱视频，掌握关键步骤后再来挑战！",
          resultColor: "#f5222d",
          resultIcon: "/images/error.png"
        });
      }
    },
  
    // 重新测试
    reTest() {
      // 清除历史答案
      wx.removeStorageSync('totalScore');
      wx.navigateTo({
        url: '/pages/quiz/quiz'
      });
    },
  
    // 查看食谱
    viewRecipe() {
      // 实际项目中跳转至食谱详情页
      wx.showToast({
        title: '跳转至番茄炒蛋食谱',
        icon: 'none',
        duration: 2000
      });
    }
  });